package com.itheima.manager;

import com.itheima.domain.UmsResource;
import com.itheima.domain.UmsRoleResourceRelation;
import com.itheima.service.db.UmsResoureService;
import com.itheima.util.R;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName UmsResoureManager
 * @date 2022/11/13 2:06
 */
@Component
public class UmsResoureManager {
    @DubboReference
    UmsResoureService umsResoureService;

    // 获取角色相关资源
    public R listResource(Long roleId) {
        List<UmsResource> umsResourceList =  umsResoureService.listResource(roleId);
        return R.success(umsResourceList);
    }

    /**
     * 分页模糊查询后台资源
     *
     * @return
     */
    public R getList(Map<String,String> map) {
        PageBeanVo resoureServiceList = umsResoureService.getList(map);
        return R.success(resoureServiceList);
    }

    /**
     * 添加后台资源
     * @param umsResource
     * @return
     */
    public R create(UmsResource umsResource) {
        umsResoureService.create(umsResource);
        return R.success("添加成功");
    }

    /**
     * 修改后台资源
     * @param id
     * @param umsResource
     * @return
     */
    public R update(Long id, UmsResource umsResource) {
        umsResoureService.update(id,umsResource);
        return R.success("修改成功");
    }

    /**
     * 根据ID删除后台资源
     * @param id
     * @return
     */
    public R delete(Long id) {
        umsResoureService.delete(id);
        return R.success("删除成功");
    }

    /**
     * 查询所有后台资源
     * @return
     */
    public R listAll() {
        List<UmsResource> umsResourceList = umsResoureService.listAll();
        return R.success(umsResourceList);
    }
}
